/**
 * Overrided memory management functions to
 * provide more controls on leak detection & log
 * 
 * This version is a simple docoration of libc APIs,
 * May add customed heep management in the future;
 */

#if defined ( __cplusplus)
extern "C"{
#endif

#include "tf_mem.h"
#include "tf_log.h"
#include <stdlib.h>

extern int tf_mem_verbose;

void* tf_malloc( size_t size){
    void* ret=malloc(size);
    if( tf_mem_verbose)
        tf_log( "[ TF_MALLOC ]: %d bytes at 0x%x\n", size, (long)(ret));
    return ret;
}

void tf_free( void* ptr){
    if( tf_mem_verbose)
        tf_log( "[ TF_FREE ] : 0x%x\n", (long)(ptr));
    free( ptr);
}

void* tf_realloc( void* ptr, size_t size){
    void* ret=realloc( ptr, size);
    if( tf_mem_verbose)
        tf_log( "[ TF_REALLOC ]: %d bytes at 0x%x\n", size, (long)(ret));
    return ret;
}

#if defined ( __cplusplus)
}
#endif

